// tsc 3-1.ts -t es6 && node 3-1.js
// 3-1声明变量
let number1 = 4;
let number2 = 2;
const number4 = 3;
// number4 = 4;
function doSomething() {
    for (let i = 0; i < 5; i++) {
        console.log(i);
    }
    // console.log("finally i=",i)
}
doSomething();
// 课程3-3: number， string, boolean
function add(n1, n2) {
    return n1 + n2;
}
console.log(add(number1, number2));
let isTrue = true;
// isTrue = "true";
let total = 0;
let firstName = 'madison';
let str = `我叫${firstName}`;
console.log(str);
// 课程3-4:  数组(array) 和元组(Tupple)
let list1 = [1, 2, 3, 4];
let list2 = [1, 2, 3, 4];
let list3 = [1, 2, 3, 4];
let list4 = [1, 'ddd'];
// list4.push(true)
let list5 = [1, 'ddd', true];
list5.push(5);
let person1 = [1, 'madison'];
// person1[0] = 'ddd'
// person1[1] = 1
// person1[2] = 111
person1.push(111);
console.log(person1);
let person2 = [1, 'madison'];
person2[0] = 'ddd';
person2[1] = 1;
person2[2] = 'ddd';
console.log(person2);
// 3-5 联合(Union)类型与文献(Literal)类型
let union;
union = 2;
union = 'madison';
// union = true
let union2;
function merge(n1, n2, resultType) {
    if (resultType == 'as-string') {
        return n1.toString() + n2.toString();
    }
    if (typeof n1 === 'string' || typeof n2 === 'string') {
        return n1.toString() + n2.toString();
    }
    return n1 + n2;
}
let mergeNumber = merge(2, 5, 'as-number');
let mergeNumber2 = merge(2, 5, 'as-string');
let mergeString = merge('hello', 'world', 'as-string');
console.log(mergeNumber);
console.log(mergeNumber2);
console.log(mergeString);
// 字面量类型
let union3 = 0 | 1 | 2;
union3 = 1;
union3 = 4;
console.log(union3);
let literal;
// 3-6 枚举类型 Enum
var Color;
(function (Color) {
    Color[Color["red"] = 5] = "red";
    Color[Color["green"] = 6] = "green";
    Color[Color["blue"] = 7] = "blue";
})(Color || (Color = {}));
var Color2;
(function (Color2) {
    Color2[Color2["red"] = 5] = "red";
    Color2[Color2["green"] = 10] = "green";
    Color2[Color2["blue"] = 1] = "blue";
})(Color2 || (Color2 = {}));
var Color3;
(function (Color3) {
    Color3["red"] = "red";
    Color3["green"] = "green";
    Color3[Color3["blue"] = 1] = "blue";
})(Color3 || (Color3 = {}));
let color = Color.blue;
console.log(color);
let color3 = Color3.green;
console.log(color3);
// 3-7 any和 unkonwn
// let randomValue:any = 666
let randomValue = 666;
randomValue = true;
randomValue = 'amasd';
randomValue = {};
if (typeof randomValue === 'function') {
    randomValue();
}
if (typeof randomValue === 'string') {
    randomValue.toUpperCase();
}
// 3-8 void、undefined 与 never
function printResult() {
    console.log('llll');
    return;
}
console.log('hello', printResult());
function throwErro(message, errorCode) {
    throw {
        message,
        errorCode
    };
}
// throwErro('not found', 404)
function whileLoop() {
    while (true) {
        console.log('hhh');
    }
}
// 3-9 类型适配(类型断言) Type Assertions
let message;
message = 'abc';
// message.endWith('c')
let ddd = message.endsWith('c');
console.log(ddd);
let ddd2 = message.endsWith('c');
console.log(ddd2);
// 3-10 函数类型
let log = function (message) {
    console.log(message);
};
let log2 = (message) => console.log(message);
log2('madison');
// log2(2)
let log3 = (message, code) => {
    console.log(message, code);
};
log3('hello', 1);
let log4 = (message, code) => {
    console.log(message, code);
};
log4('hello');
let log5 = (message, code = 0) => {
    console.log(message, code);
};
log5('hello');
